<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <meta name="author" content="Mouse0w0">
  
  <link rel="shortcut icon" href="../img/favicon.ico">
  <title>附录 A - OpenGL调试 - Lwjglbook中文翻译</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="../css/theme.css" />
  <link rel="stylesheet" href="../css/theme_extra.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "\u9644\u5f55 A - OpenGL\u8c03\u8bd5";
    var mkdocs_page_input_path = "a01-opengl-debugging.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../js/jquery-2.1.1.min.js" defer></script>
  <script src="../js/modernizr-2.8.3.min.js" defer></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href=".." class="icon icon-home"> Lwjglbook中文翻译</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../01-first-steps/">事前准备</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../02-the-game-loop/">游戏循环</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../03-a-brief-about-coordinates/">坐标简介</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../04-rendering/">渲染</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../05-more-on-rendering/">渲染补充</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../06-transformations/">变换</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../07-textures/">纹理</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../08-camera/">摄像机</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../09-loading-more-complex-models/">加载更复杂的模型</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../10-let-there-be-light/">要有光</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../11-let-there-be-even-more-light/">要有更多的光</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../12-game-hud/">游戏HUD</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../13-sky-box-and-some-optimizations/">天空盒与一些优化</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../14-height-maps/">高度图</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../15-terrain-collisions/">地形碰撞</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../16-fog/">雾</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../17-normal-mapping/">法线贴图</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../18-shadows/">阴影</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../19-animations/">动画</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../20-particles/">粒子</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../21-instanced-rendering/">实例化渲染</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../22-audio/">音效</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../23-3d-object-picking/">三维物体选取</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../24-hud-revisited/">回顾HUD - NanoVG</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../25-optimizations-frustum-culling/">优化 - 截锥剔除</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../26-cascaded-shadow-maps/">级联阴影映射</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../27-assimp/">Assimp库</a>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../28-deferred-shading/">延迟着色法</a>
                    </li>
                </ul>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="./">附录 A - OpenGL调试</a>
    <ul class="current">
    </ul>
                    </li>
                </ul>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../glossary/">术语表</a>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="..">Lwjglbook中文翻译</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="..">Docs</a> &raquo;</li>
    
      
    
    <li>附录 A - OpenGL调试</li>
    <li class="wy-breadcrumbs-aside">
      
        <a href="https://github.com/Mouse0w0/lwjglbook-CN-Translation/edit/master/docs/a01-opengl-debugging.md"
          class="icon icon-github"> Edit on GitHub</a>
      
    </li>
  </ul>
  
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h1 id="a-openglopengl-debugging">附录 A - OpenGL调试（OpenGL Debugging）</h1>
<p>调试OpenGL程序可能是一项艰巨的任务。在大多数情况下，你会看到一个黑屏，你无法知道到底发生了什么。为了缓解这个窘况，我们可以使用一些现有的工具来提供关于渲染流程的更多信息。</p>
<p>在本附录中，我们将学习如何使用<a href="https://renderdoc.org/" title="RenderDoc">RenderDoc</a>工具调试LWJGL程序。RenderDoc是一个图形调试工程，可以与Direct3D、Vulkan和OpenGL一起使用。对于OpenGL，它仅支持从3.2到4.5的核心模式。</p>
<p>让我们开始吧，你需要下载并安装对应操作系统的RenderDoc。安装后，当你启动它时，会看到类似于下图的东西：</p>
<p><img alt="RenderDoc" src="../_static/a01/renderdoc.png" /></p>
<p>第一步是配置RenderDoc来运行和监视我们的示例。在“Capture Executable”选项卡中，需要设置以下参数：</p>
<ul>
<li><strong>Executable path</strong>：在本例中，这应该指向JVM启动程序（例如，“C:\Program Files\Java\jdk-9\bin\java.exe”）。</li>
<li><strong>Working Directory</strong>：这将为你的程序设置工作目录。在本例中，应该将其设置为Maven转储结果的<code>target</code>目录。这样设置后，可以找到依赖项。</li>
<li><strong>Command line arguments</strong>：这将包含JVM运行示例所需的参数。在本例中，只需要传递要执行的Jar（例如，“-java game-c28-1.0.jar”）。</li>
</ul>
<p><img alt="运行参数" src="../_static/a01/exec_arguments.png" /></p>
<p>你要记住3D模型现已由<a href="http://assimp.sourceforge.net/" title="Assimp">Assimp</a>库加载，我们需要的是实际的文件路径（而不是<code>CLASSPATH</code>的相对路径），因此你需要在你设置的工作目录检查路径。在此情况下，最简单快速的测试方法是将src文件夹复制到<code>target</code>目录中。</p>
<p>此选项卡中还有许多其他选项用于配置捕获选项。你可以在<a href="https://renderdoc.org/docs/index.html" title="RenderDoc文档">RenderDoc文档</a>中查阅它们的用途。一切就绪后，你可以通过点击“Launch”按钮来开始运行程序。你将看到如下内容：</p>
<p><img alt="示例" src="../_static/a01/sample.png" /></p>
<p>你可能会看到一个警告，因为RenderDoc只能使用OpenGL核心模式。在本例中，我们已经启用了兼容性模式，但它会忽略警告继续工作。程序运行后，你就可以触发它的快照。你将看到添加了一个新的选项卡，名为“java [PID XXXX]”（其中XXXX数字表示Java进程的PID、进程标识号）</p>
<p><img alt="Java进程" src="../_static/a01/java_process.png" /></p>
<p>从该选项卡中，你可以通过按下“Trigger capture”按钮来捕获程序的状态。生成了一个捕获结果后，你将在同一个选项卡中看到一个小快照。</p>
<p><img alt="捕获" src="../_static/a01/capture.png" /></p>
<p>如果双击该捕获结果，则将加载收集的所有数据，并可以开始查看它。“Event Browser”面板将显示所有在一个渲染周期内执行的与OpenGL相关的调用。</p>
<p><img alt="事件浏览器" src="../_static/a01/event_browser.png" /></p>
<p>对于第一个渲染流程，你可以看到地面是如何在模型房屋的网格之后绘制的。如果单击一个glDrawELements事件，并选择“Mesh”选项卡，则可以查看绘制的网格，事件的顶点着色器的输入与输出。</p>
<p>你换可以查看用于该绘制操作的输入纹理（通过单击“Texture Viewer”选项卡）。</p>
<p><img alt="纹理输入" src="../_static/a01/texture_inputs.png" /></p>
<p>在中央面板中，你可以看到输出，在右侧面板上可以看到用于输入的纹理列表。还可以逐个查看输出纹理。这很好地说明了延迟着色是如何工作的。</p>
<p><img alt="纹理输出" src="../_static/a01/texture_outputs.png" /></p>
<p>如你所见，该工具提供了有关渲染时发生的情况的宝贵数据，它可以在调试渲染问题时节省宝贵的时间。它甚至可以显示有关渲染管线中使用的着色器的信息。</p>
<p><img alt="管线状态" src="../_static/a01/pipeline_state.png" /></p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../glossary/" class="btn btn-neutral float-right" title="术语表">Next <span class="icon icon-circle-arrow-right"></span></a>
      
      
        <a href="../28-deferred-shading/" class="btn btn-neutral" title="延迟着色法"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
      <p>2019, Mouse0w0</p>
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a href="https://github.com/Mouse0w0/lwjglbook-CN-Translation/" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../28-deferred-shading/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
        <span style="margin-left: 15px"><a href="../glossary/" style="color: #fcfcfc">Next &raquo;</a></span>
      
    </span>
</div>
    <script>var base_url = '..';</script>
    <script src="../js/theme.js" defer></script>
      <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" defer></script>
      <script src="../search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>
